import React, { Component } from 'react'
import {ThemeContext} from './Context';

class Left extends Component {
    render() {
        return (
            <div>
                <ThemeContext.Consumer>
                    {
                        //从传递过来的value中直接解构出changeColor
                        ({changeColor})=><button onClick={changeColor}>更换主题</button>
                    }
                </ThemeContext.Consumer>
                <button onClick={this.context.changeColor}>更换主题</button>
            </div>
        )
    }
}

Left.contextType = ThemeContext;//把ThemeContext直接绑定到类组件的context属性上，在使用时就不需要写ThemeContext.Consumer了，直接在this中调用即可

export default Left;